﻿using FunctionalCLR.Core;

namespace Zove.Runtime.FunctionalCLR {
    
    /// <summary>
    /// 
    /// </summary>
    public class ZoomParser : Parser {

        private RuntimeModel rm = null;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="rm"></param>
        public ZoomParser(string expr, RuntimeModel rm)
            : base(expr) {
            this.rm = rm;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public override Node GetVariableNode(string value) {
            FactorNode fn = new FactorNode();
            fn.Factor = rm.GetFactorByName(value);
            if (fn.Factor == null) {
                throw new FactorNotDeclaredException(
                    value, base.lexer.LineNumber, rm.Name);
            }

            return fn;
        }
    }
}
